#include "NodeVisitor.h"

#include <iomanip>

using namespace std;

void EnvironmentVisitor::DefaultVisit(ParseNode *n) {
	

}

void EnvironmentVisitor::visit(MethodDeclarationNode *n) {
	map<DeclarationNode::Namespace, std::set<TypedNode*, compare_decls> > elements_in_scope = n->elements_in_scope;
	map<DeclarationNode::Namespace, std::set<TypedNode*, compare_decls> >::iterator it;

	out << n->Type() << endl;


	for (it = elements_in_scope.begin(); it != elements_in_scope.end(); ++it){

		out << it->first << endl;

		for (std::set<TypedNode*, compare_decls>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
			out << '	' << (*it2)->identifier << endl;

	}

}

void EnvironmentVisitor::visit(ClassDeclarationNode *n) {

	map<DeclarationNode::Namespace, std::set<TypedNode*, compare_decls> > elements_in_scope = n->elements_in_scope;
	map<DeclarationNode::Namespace, std::set<TypedNode*, compare_decls> >::iterator it;

	out << n->Type() << endl;


	for (it = elements_in_scope.begin(); it != elements_in_scope.end(); ++it){

		out << it->first << endl;

		for (std::set<TypedNode*, compare_decls>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
			out << '	' << (*it2)->identifier << endl;

	}

}

